package service;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import dao.IInfoModDao;
import po.User;

public class InfoModService implements IInfoModService{
	private IInfoModDao infoModDao;
	private Map<String, Object> request, session;
	public User getUser(int id) {
		return infoModDao.getUser(id);
	}

	public boolean updateUser(User user,int id) {
		ActionContext ctx= ActionContext.getContext();
		session=(Map) ctx.getSession();
		request=(Map) ctx.get("request");
		User newUser = getUser(id);
		newUser.setAccount(user.getAccount());
		newUser.getUserDetail().setName(user.getUserDetail().getName());
		newUser.setPassword(user.getPassword());
		newUser.getUserDetail().setBirthday(user.getUserDetail().getBirthday());
		newUser.getUserDetail().setPhone(user.getUserDetail().getPhone());
		newUser.getUserDetail().setEmail(user.getUserDetail().getEmail());
		
		infoModDao.update(newUser);  
		request.put("tip", "信息修改成功");
		return true;
	}

	public IInfoModDao getInfoModDao() {
		return infoModDao;
	}

	public void setInfoModDao(IInfoModDao infoModDao) {
		this.infoModDao = infoModDao;
	}
}
